package com.cloud.bssp.java8.TestAsync;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.NamedThreadFactory;

import java.util.Date;
import java.util.concurrent.*;

/**
 * @description： Future学习
 * @author：weirx
 * @date：2021/10/28 14:01
 * @version：3.0
 */
public class TestFuture {

    static String test() throws InterruptedException {
        Thread.sleep(10000);
        return "test Future";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));

        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                5,
                10,
                60,
                TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
                new NamedThreadFactory("Future", false)
        );
        Future<String> future = executor.submit(TestFuture::test);
        System.out.println("eat something。。。。");
        System.out.println("drink something。。。。");
        System.out.println(future.get());
        System.out.println(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
    }
}
